<?php
namespace app\common\model;

use app\common\model\BaseModel;
use think\facade\Request;

/**
 * 分享数据库定义
 */
class ShareCode extends BaseModel
{

    /**
     * 定义字段类型
     * @var array
     */
    protected $type = [
        'id'        => 'integer',
        'code'		=> 'string',
        'param'    	=> 'json',
    ];

    /**
     * 获取分享用户
     * Author 亓官雨树<lucky.max@foxmail.com>
     * Date 2021-06-21
     * @return [type] [description]
     */
    public static function getShareUser()
    {
    	$share_code = Request::header('e-share-code');
        if ($share_code) {
            $share_data = app(ShareCode::class)->whereCode($share_code)->findOrEmpty();
            if ( !$share_data->isEmpty() ) {
                $param = $share_data->param;
                return $param['mid'];
            }
        }
        return 0;
    }
}
